const
    http = require("http"),
    fs = require("fs"),
    dru = '/Volumes/jacky/web-sd/nodeStudy/day01/html';

http.createServer((request, response) => {

    let nurl = request.headers.referer,
        res = response,
        Url = request.url,
        fileUrl = dru + Url;

    // if (nurl) {
    //     pathto = nurl.split('/').slice(3).join('/');
    //     console.log(pathto);
    // }
    openFile(res, fileUrl);

}).listen(7000);


function openFile(res, path) {
    fs.readFile(path, (err, data) => {

        if (err) {
            res.writeHead(404, { "Content-Type": "text/html;charset=\"utf-8\"" });
            res.end('404');

        } else {

            res.writeHead(200, { "Content-Type": "text/html;charset=\"utf-8\"" });
            res.write(data);
            res.end();

        }

    });
}